Script hello
    Print("zj Test");
EndScript

Script whiledemo
    U0 x=0;
    while(x<10)
    {
        PrintLn(x);
        Inc(x);
    }
	IDelete(x);
	PrintLn(x);
EndScript



Script SwitchDemo2

String s;
s = "B";

switch (s)
{
	case "A"
		Print ("Apple");
		break;
		
	case "B"
		Print ("Ball");
		break;
		
	case "C"
		Print ("Cow");
		break;
		
	default
		Print ("Could be anything");
		break;
}

PrintLn ("This is after the switch block");

EndScript

Script CPoint
U4 x, y;
x = 3;
y = 4;
Show();
Script Show
PrintLn (x);
PrintLn (y);
EndScript		//ending Show
EndScript		//ending CPoint

Script T
String s = "Hello world";
U4 len;
len = StrLen(s); //StrLen is a function call
PrintLn(len);	
PrintLn(StrLen(s));	//return value as a parameter to subroutine call
//StrLen(s);		//this is illegal, because return value cannot be ignored
EndScript

Script VectorDemo
Vector x,y;
VectorPush(x, "Hello world");
PrintLn(x);
VectorPush(x, 123);
PrintLn(x);
VectorPush(y, x);
PrintLn(y);

// VectorInsert(x,1,12);
// PrintLn(x);
// VectorPop(x);
// PrintLn(x);
// VectorRemove(x,1);
// PrintLn(x);
// //VectorClear(x);
// PrintLn(x);
// // PrintLn(x[0]);
// PrintLn(x[0]);
EndScript



Script MapDemo

IMap c,cassinfo;
String a = "cass_id";
String b = "12";

IMapPush(c,"cass_id",b);
PrintLn(c);
PrintLn(c[0]);

// IMapPush(cassinfo, "cass_id","vOut[0][i]");
// 		IMapPush(cassinfo, "cass_type","vOut[4][i]");
// 		IMapPush(cassinfo, "eqp_info","vOut[1][i]");
// 		IMapPush(cassinfo, "flow_out_time","vOut[2][i]");
// 		IMapPush(cassinfo, "wafer_count","vOut[3][i]");
// 		PrintLn(cassinfo[1]);

	
		
// Vector a;
// Reference p;
// MapAdd(x, "A_A", "Apple");
// MapAdd(x, "B", "Ball");
// MapAdd(b, "A", "Apple");
// MapAdd(b, "B", "Ball");
// PrintLn(x["A_A"]);

// PrintLn(IFindEx(p, b, "A"));
// if (IFindEx(p, b, "A"))
// {
// 	PrintLn(p);
	
// 	PrintLn("1212");
	
// }
// VectorPush(x, "B", "Ball");
// PrintLn(x["A"]);
// PrintLn(x["B"]);
// MapEnumKey();
// PrintLn(x);
// MapAdd(x, "B", "Ball1");
// PrintLn(x);
// MapRemove(x,"A");
// PrintLn(x);
// VectorPush(a, x);
// VectorPush(a, b);
// IMapPush(c,"Marklist", a);
// PrintLn(c);

EndScript

Script QueueDemo
Queue x;
QueuePushBack(x, 222);
QueuePushBack(x, 333);
QueuePushFront(x, 111);
PrintLn(QueueFront(x));
PrintLn(QueueBack(x));
PrintLn(x);
EndScript

Script IMapDemo
IMap x;
IMapPush(x, "B_1", "Ball");
ObjDelete(x);
PrintLn(x);
String a = "A";
IMapInsert(x, 0, "A", "Apple");
PrintLn(x[a]);
PrintLn(x[|"A"|]);	//string index
// PrintLn(x[1]);		//numerical index
// PrintLn(IMapGetKey(x, 0));		//get the string index using numerical index
// PrintLn(IMapGetIndex(x, "B"));//get the numerical index using string index·
EndScript

Script T1
// GCreate("IBM", "International Business Machine");
// // PrintLn(IBM);
// PrintLn(Global["IBM"]);
// PrintLn(:IBM);
U0 ret;
// LibLoad(LinWin("./libQSECS.so", "QSECS.dll"), "Secs", ret);
// PCall("WcsUpdateDestination", j["mission_id"]);
PCall("testtesttesttets");
EndScript

Script T2
String s = "IBM";
PrintLn(:s);			//this is interpreted as Global[s]
EndScript

Script T3
PrintLn(:IBM);			//this is interpreted as Global["IBM"]
EndScript

Script Stringtest
	String a ;
	PrintLn(StrLen(a));
	
EndScript

Script ToX

PrintLn(StrToX("123", "U4"));
PrintLn(StrToX("123", "F8"));
PrintLn(StrToX("Hello", "I4"));		//this will cause exceptionw

EndScript

Script replace
String s = "Hello";
StrReplace(s, "ll", "r");
PrintLn(s);

StrReplace(s, 0, 3, "Amig");
PrintLn(s);
EndScript

Script compare
String s = "Hello";
PrintLn(StrCmp("Hello", s));
PrintLn(StrCmp("123", 120));
PrintLn(StrCmp("123", 122+1));
PrintLn(StrCmp("123", 125));
EndScript

Script TimeoutChecker
	(host, nodeAlias, timeoutType)
	U8 waitTotal = 0;
	U4 timeout = 0;
	if (timeoutType == "T1")
	{
		timeout = 4000;
	} else {
		timeout = 2000;
	}
	while(1)
	{
		Object value;
		U4 ret;
		:host.Read(nodeAlias, value, ret);
		if(value)
		{
			if (timeout == waitTotal)
			{
				OPCLog("[ERROR] [", ScriptName(), "] {", nodeAlias, "} ", timeoutType, " timeout, will set to off.");
				:host.Write(nodeAlias, 0, ret);
				wbreak;
			}
		} else {
			wbreak;
		}
		Sleep(100);
		waitTotal = waitTotal + 100;
	}
EndScript

Script OpcT1Check
	(host, nodeAlias)
	PCall("TimeoutChecker", host, nodeAlias, "T1");
EndScript

Script OpcT2Check
	(host, nodeAlias)
	PCall("TimeoutChecker", host, nodeAlias, "T2");
EndScript

Script time
PrintLn(StrTime("Date time in 24 hours format %Y/%M/%D %h:%m:%s.%S %A"));
PrintLn(StrTime("Date time in 12 hours format %Y/%M/%D %H:%m:%s.%S %a"));
PrintLn(StrTime("%1 %2 %3 %4 %5"));
PrintLn(StrTime("%1 %2 %3 %4 %5", 2)); //note the zero values int
EndScript

Script FindFirstNot
//字符查找 查找从offset位置开始首次出现在前一个一次而未出现在后一个字符的位置
U0 offset = 2;
U0 pos = StrFindFirstNot("Telecommunication", offset, "aeioul");
if (pos == -1)
{
	PrintLn("Non vowel not found");
}
else
{
	PrintLn("Starting search at position ", offset, ", non-vowel found at position ", pos);
}
EndScript

Script FindLast
U0 offset = 7;
U0 pos = StrFindLast("Telecommunication", offset, "aeiou");
if (pos == -1)
{
	PrintLn("No vowel found");
}
else
{
	PrintLn("Starting search at position ", offset, ", vowel found at position ", pos);
}
EndScript

Script FindLastNot
	U0 offset = 7;
	U0 pos = StrFindLastNot("Telecomamunication", offset, "aeiou");
	if (pos == -1)
	{
		PrintLn("No vowel found");
	}
	else
	{
		PrintLn("Starting search at position ", offset, ", non-vowel found at position ", pos);
	}
EndScript

Script Find
	U4 selectpos,frompos;
	String a = "select * from rtd.wcs_station_port_base_cfg wspbc where proc_type = '1#' and loop_id = 2";
	Vector v;
	if (StrFind(a, "select", 0, selectpos))
	{
		PrintLn("Found at ", selectpos);
	}
	else
	{
		PrintLn("Not found");
	}
	if (StrFind(a, "from", 0, frompos))
	{
		PrintLn("Found at ", frompos);
	}
	else
	{
		PrintLn("Not found");
	}
	StrTok(a, selectpos + 6, frompos, ",", v);
	PrintLn(v);
	
EndScript

Script strtok
	Vector v;
	U0 i;
	Reference p;
	String s = "4#-8HT-1O,4#-7HT-1O,4#-6HT-1O,4#-5HT-1O,4#-4HT-1O,4#-3HT-1O";  //note the adjacent delimiter
	// PrintLn(s);
	StrTok(s, 0, 0, ",", v);
	foreach(p, v, i)
	{
		PrintLn(StrLen(p), " - ", p);
	}
EndScript

Script strtokex
	Vector v;
	U0 i;
	Reference p;
	String s = "1,2,3,4,,,,5";
	StrTokEx(s, 0, 0, ", ", v);
	foreach(p, v, i)
	{
		PrintLn(StrLen(p), " - ", p);
	}
EndScript

Script strrepeat
	String s;
	StrRepeat(s, 3 + 4, 3);
	PrintLn(s);
EndScript

Script strassign
	String s;
	StrAssign(s, "Hello ", 3 + 4,1,1,1);
	PrintLn(s);
EndScript

Script strappend
	//不同于strassign，strappend不需要清除原变量 直接拼接在一起
	String s = "Hello";
	StrAppend(s, " world ", 3 + 4);
	PrintLn(s);
EndScript

Script strreadfile
	//整个文件一起读 存储进一个String
String s;
if (StrReadFile(s, "S1.txt"))
{
	PrintLn("Failed to read file");
}
else
{
	PrintLn(s);
}
EndScript

Script ReadLine
	String s,s2;
	Vector v;
	U0 i;
	Reference p;
	if (StrReadFile(s, "S1.txt"))
	{
		PrintLn("Failed to read file");
	}
	else
	{
		// PrintLn(StrHex(s));
		StrTokEx(s, 0, 0, "\x0D", v);
		foreach(p, v, i)
		{
		StrReplace(p,"\x0D","");
		StrReplace(p,"\x0A","");
		// PrintLn(p," = ",StrHex(s2));
			Print(p);
			

		}
		PrintLn("");

	}
EndScript

Script strappendfile
String s = "xxx\x0D";
if (StrAppendFile(s, "S1.txt"))
{
	PrintLn("Failed to append file");
}
else
{
	PrintLn("Append is successful");
}
EndScript

Script basicfun
	U0 x=0;
	Vector v;
	VectorPush(v,"1212");
	VectorPushEx(v,"23323233",1212);
	PrintLn(v);
	VectorPush(v,"3232");
	VectorPush(v,"3233");
	VectorPush(v,"3234");
	VectorPush(v,"3235");
	VectorPush(v,"3236");
	PrintLn(v);
	PrintLn(GetType(x)) ;
	PrintLn(GetActualType(x)) ;
	PrintLn(GetCount(v));
EndScript

Script Elapse

	U4 loop = 10000000;
	U4 T1 = GetTick();
	while (Dec(loop))
	{}
	U4 T2 = GetTick();

	PrintLn ("Time elapsed is ", T2 - T1, " ms");

EndScript


Script randtest
	U4 x=Rand();
	PrintLn(x);
	PrintLn(ScriptName());
EndScript

Script TickTest
	U4 t0 = GetTick();
	AppLog("[GetTick]: ");
EndScript

Script abab
String tmp,prev_proc,loop_id;
prev_proc = "9#";
loop_id = "12";

StrAssign(tmp, "select station_port, water_mark   from rtd.wcs_station_port_base_cfg where term = '2' and proc_type = '", prev_proc, "' loop_id = ",loop_id);
PrintLn(tmp);

EndScript


Script SubWaterMarkinfo
(mark1, mark2, mark3, mark4, mark5)
U0 Sub_Water_Mark_1 = mark1;
U0 Sub_Water_Mark_2 = mark2;
U0 Sub_Water_Mark_3 = mark3;
U0 Sub_Water_Mark_4 = mark4;
U0 Sub_Water_Mark_5 = mark5;
EndScript


Script sumSubWaterMark
(host, alias, value)
Reference p;
if (IFindEx(p, :SubWaterMarkCount, host) == 0)
{
	MapAddEx(:SubWaterMarkCount, host, "SubWaterMarkinfo", 0, 0, 0, 0, 0);
}

PrintLn(GetActualType(:SubWaterMarkCount[host]));
PrintLn(:SubWaterMarkCount[host]);
:SubWaterMarkCount[host][alias] = value;
EndScript

Script t4
	GCreateEx("SubWaterMarkCount", "Map");
	sumSubWaterMark("11#", "Sub_Water_Mark_2", 2);
	sumSubWaterMark("11#", "Sub_Water_Mark_5", 999);
	PrintLn(:SubWaterMarkCount);

	U0 count = :SubWaterMarkCount["11#"]["Sub_Water_Mark_1"] 
		+ :SubWaterMarkCount["11#"]["Sub_Water_Mark_2"]
		+ :SubWaterMarkCount["11#"]["Sub_Water_Mark_3"]
		+ :SubWaterMarkCount["11#"]["Sub_Water_Mark_4"]
		+ :SubWaterMarkCount["11#"]["Sub_Water_Mark_5"];
	PrintLn(count);
EndScript


Script ee
String t;
String s = "0a8bb49ef6e515120bc98879198d3490393a52ca";
StrConvertHex(t, s);
PrintLn(StrHex(t));

StrWriteFile(t, "test.bin");
EndScript

Script ff
String s = "Cy5NgC6jFNx3j8XZKpMaKw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
String sha, base64;
if (StrSHA1(sha, s))
{
	StrToBase64(base64, sha);
	PrintLn(base64);
}

EndScript


Script TT
	Object j;
	U0 a = 0;
	GetJSON("cassinfo", j);
	PrintLn(GetActualType(j));
	PrintLn(ifexp(a == 0)(1)(2));
EndScript



Resource cassinfo
{
	"cass_id":"",
	"cass_type":"",
	"eqp_info":"",
	"flow_out_time":"",
	"wafer_count":""
}
EndResource


Script test111
	String pattern1, pattern2;
	StrAssign(pattern1, "9#", "*");
	StrAssign(pattern2, "10#", "*");
	String target = "9#-12HT-1O";
	
	StrReplace(pattern1, "#", "@");
	StrReplace(pattern2, "#", "@");
	StrReplace(target, "#", "@");
	
	PrintLn(Pattern(target, pattern1));
	PrintLn(Pattern(pattern1, target));
	PrintLn(Pattern(target, pattern2));
EndScript

Script sjn
	Vector aa;
	VectorPush(aa, "apple");
	VectorPush(aa, "ball");
	PrintLn(aa);
	
EndScript


Script LoadPC
Object j;
U0 i;
String key;
Reference p;
if (GetJSONFile("PC.json", j))
{
	AppLog("Failed to read PC.json");
	return;
}

//MapClear(:PC);
foreach(p, j, i, key)
{
	AppLog(p.xxx);
	//MapAddEx(:PC, key, "CPC", p.Alogo, p[1]);
}

//AppLog("[PC]\x0A", :PC);
EndScript

Script AAAAA
	String s = "21111111";
	if(s == "1212")
	{
		PrintLn("1212");
		
	}
	elseif(s == "2121")
	{
		PrintLn("2121");
		
	}
	else
	{
		PrintLn("2222");
		
	}
EndScript

Script qqq
	String a = "2024-04-10 02:09:37.661700";
	String b = "2024-04-10 00:43:40";
	
	PrintLn(GetFT(a));
	PrintLn(GetFT(b));
	PrintLn(ABS(GetFT(a),GetFT(b)));
	U8 c = 24000000000;
	U8 d = GetFT(a) - GetFT(b);
	PrintLn(c);
	
	PrintLn(d);
	
	
EndScript


Script ABS
(a, b)
if(a >= b)
{
	return a - b;
}
else
{
	return b - a;
}
EndScript

Script ppp
Vector v,vroute;
Reference pTool,pRoute;
U0 flag1;
VectorPush(v,"17#-1LT-2I");
VectorPush(v,"17#-2LT-2I");
VectorPush(v,"17#-3LT-2I");
VectorPush(v,"17#-4LT-2I");
VectorPush(vroute,"17#-3LT-2I");
VectorPush(vroute,"17#-4LT-2I");
VectorPush(vroute,"17#-5LT-2I");
VectorPush(vroute,"17#-6LT-2I");
VectorPush(vroute,"17#-7LT-2I");
VectorPush(vroute,"17#-8LT-2I");
foreach(pTool, v)
{
	flag1 = 0;
	foreach(pRoute, vroute)
	{
		//flag1 = 0;
		if(pRoute == pTool)
		{
			flag1 = 1;
			fbreak;
		}
		PrintLn(pTool," - ",pRoute, "    Flag is ",flag1);
	}
	if(flag1 == 0)
	{
		IDelete(pTool);
		fcontinue;
	}
}
PrintLn(v);

EndScript


Script www
Vector v;
VectorPush(v,"1212");
VectorPush(v,"12212");
VectorPush(v,"1232312");
PrintLn(VectorBack(v));
EndScript


Script stest
	IMap a;
	Vector b;
	IMapPush(a,"id","12");
	IMapPush(a,"name","sjn");
	VectorPush(b,a);
	IMapClear(a);
	IMapPush(a,"id","12");
	IMapPush(a,"name","sjn11");
	VectorPush(b,a);
	PrintLn(b);
	static String q;
EndScript